package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryBrandService;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CategoryBrandService categoryBrandService;


    /*查询所有(cid=0)*/
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBid(@RequestParam("pid") Long pid) {

        List<CategoryDTO> list = categoryService.queryCategoryByBid(pid);
        ResponseEntity<List<CategoryDTO>> ok = ResponseEntity.ok(list);
        return ok;
    }

    /*根据ID查询分类*/
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryByid(@PathVariable("id") Long id) {

        CategoryDTO one = categoryService.queryCategoryByid(id);

        return ResponseEntity.ok(one);
    }

    /*根据分类id集合来查询分类商品*/
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(
            @RequestParam("ids")List<Long> ids){

        return ResponseEntity.ok(this.categoryService.queryCategoryByIds(ids));
    }

    /*根据品牌ID查分类集合*/
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategorybybrandid(@RequestParam("id") Long bid) {
        List<CategoryDTO> list = categoryBrandService.queryCategorybybrandid(bid);
        return ResponseEntity.ok(list);

    }



}
